package me.ingxin.android.sample.lego.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import me.ingxin.android.router.annotaions.Route
import me.ingxin.android.router.route.Result
import me.ingxin.android.router.route.RouteHolder
import me.ingxin.android.router.utils.*
import me.ingxin.android.sample.lego.R
import me.ingxin.android.sample.lego.databinding.ActivityTest2Binding

/**
 * Created by ingxin on 2022/4/26
 */
@Route("/activity/test2", hold = true)
class Test2Activity : AppCompatActivity() {

    private val binding by lazy { ActivityTest2Binding.inflate(layoutInflater) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        supportActionBar?.title = "/activity/test2, hold功能"

        val a = intent.getIntWrap("a",0)
        val b = intent.getBooleanWrap("cbd",false)
        val ext1 = intent?.getStringExtra("ext1")
        binding.tvShow.text = "a = $a,\next1 = $ext1,\ncbd = $b"

        binding.btnHold.setOnClickListener {
            val result = Result(Result.SUCCEED)
            result.putString("hold_key","hold时间戳${System.currentTimeMillis()}")
            //启用了hold，通知回调结果
            RouteHolder.instance.releaseActivity(this, result)
        }

        binding.btnBack.setOnClickListener {
            setResult(Activity.RESULT_OK, Intent().apply {
                putExtra("result_key","接收到Test2Activity时间戳${System.currentTimeMillis()}")
            })
            onBackPressed()
        }

        RouteHolder.instance.printRequestMap()

    }

    override fun finish() {
        super.finish()
        overridePendingTransition(0,R.anim.act_out2)
    }


}